<template>
    <div>
        <h1>房号添加</h1>

        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>房号</td>
                    <td>
                        <input type="text" v-model="info.card"/>
                    </td>
                </tr>
                <tr>
                    <td>房号名称</td>
                    <td>
                        <input type="text" v-model="info.houseTypeName"/>
                   
                    </td>
                </tr>
                <tr>
          <td align="right">门店图片</td>
          <td>
            <input type="file" @change="img" />
            <img
              :src="info.photo"
              width="100"
              height="100"
              v-if="info.photo != ''"
            />
          </td>
          
        </tr>
        
                <tr>
                    <td>
                        <button @click="add">添加</button>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import axios from 'axios';
import moment from 'moment';
import { useRouter, useRoute } from 'vue-router';

const router = useRouter();
const route = useRoute();

let info:any = reactive({
    card: "",
  houseTypeName: "",
  photo: "",

  
});
const img =(img1:any)=>{
    let obj=img1.target.files[0];
    let f=new FormData();
    f.append('fore',obj)
    axios({
        url:'/api/tu/img',
        data:f,
        method:'post',
        
        
    })
    .then(res=>{
        info.photo=res.data;
    })
}
const add = () => {
    axios({
        url: '/api/HouseType/housetypeAdd',
        method: 'post',
        data: info, 

    }) 
    .then(res => {
        if(res.data>0)
    {
        alert('添加成功');
        router.push('/HouseType'); 

    }
    else{
        alert('添加失败');
        return;
    }
       
    })
    .catch(err => {
        console.log( err);
    
    })
}
</script>

<style scoped>

</style>    